define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'alluser/alluser/index' + location.search,
                    add_url: 'alluser/alluser/add',
                    edit_url: 'alluser/alluser/edit',
                    del_url: 'alluser/alluser/del',
                    multi_url: 'alluser/alluser/multi',
                    import_url: 'alluser/alluser/import',
                    table: 'age_user_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'unionid', title: __('Unionid'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'headerimgurl', title: __('Headerimgurl'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'sex', title: __('Sex')},
                        {field: 'parent_trade', title: __('Parent_trade')},
                        {field: 'trade', title: __('Trade')},
                        {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        {field: 'password', title: __('Password'), operate: 'LIKE'},
                        {field: 'verification', title: __('Verification'), operate: 'LIKE'},
                        {field: 'status', title: __('Status')},
                        {field: 'intro', title: __('Intro'), operate: 'LIKE'},
                        {field: 'viptype', title: __('Viptype')},
                        {field: 'vipprice', title: __('Vipprice'), operate:'BETWEEN'},
                        {field: 'vipsource', title: __('Vipsource'), operate: 'LIKE'},
                        {field: 'vipstarttime', title: __('Vipstarttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'vipendtime', title: __('Vipendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'sessionkey', title: __('Sessionkey'), operate: 'LIKE'},
                        {field: 'created', title: __('Created')},
                        {field: 'lastuptime', title: __('Lastuptime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});